package com.cike.productmanager.activity;

import java.io.File;
import java.util.Properties;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.widget.Toast;

import com.cike.productmanager.R;
import com.cike.productmanager.util.DataApplication;
import com.cike.productmanager.util.EditProperties;
import com.cike.productmanager.util.MyUtil;

public class WelcomeActivity extends Activity {

	boolean isonline = false;
	private static long DALEYMILLIS = 2000; 
	
	public static final File SAVEPATH = new File(Environment.getExternalStorageDirectory() + "/ProductChannelmanager");
	public static File proFile=null;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome);
//		relativeLayout = (RelativeLayout) this.findViewById(R.id.welcomelayout);
		isonline = MyUtil.getNetworkConnectionType(getApplicationContext());
		
        new Handler().postDelayed(new Runnable() {  
        	public void run() {
        		EditLocaltion();
                DataApplication.RemoveDataAll();
                DataApplication.Init();
                
        		IsOnline();
        	}  
        }, DALEYMILLIS); 
		
	}

	
	private void EditLocaltion(){
		try {
			if(!SAVEPATH.exists()){
				SAVEPATH.mkdirs();
			}
			proFile=new File(SAVEPATH,"SysParameter");
			

			Properties prop=new Properties();
			

			
			EditProperties.saveConfig(proFile,prop);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void IsOnline() {

		if (isonline) { 
//			Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
//			startActivity(intent);
//			WelcomeActivity.this.finish(); 
//			overridePendingTransition(R.anim.myanim_in,R.anim.myanim_out);
		} else {
			AlertDialog dialog = new AlertDialog.Builder(this)
				.setTitle("提示")
					.setMessage("当前网络不可用,是否进入离线")
					.setIcon(R.drawable.dialogicon1)
					.setNegativeButton("取消",new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {
									finish();
								}
							}).setPositiveButton("确定", new OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							Toast.makeText(getApplicationContext(), "ok", 3).show();
						}
					}).create();
			dialog.show();
		}

	}
}
